//
//  OrderDetaileViewController.m
//  mhome
//
//  Created by YaSha_Tom on 2018/12/5.
//  Copyright © 2018年 刘春雷. All rights reserved.
//

#import "OrderDetaileViewController.h"
#import "OrderDetaileTableViewCell.h"
#import "DataManager.h"

@interface OrderDetaileViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UIScrollView  *scroll;    //阶段选择的滑动效果
@property (nonatomic,copy) NSArray *dataSourceArray;
@property (nonatomic,strong) NSMutableArray *sourceArray;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSArray *array;

@end

@implementation OrderDetaileViewController
- (NSMutableArray *)sourceArray {
    if(!_sourceArray){
        _sourceArray = [NSMutableArray array];
    }
    return _sourceArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title =@"订单详情";
   
    self.view.backgroundColor = [UIColor whiteColor];
    [self initUI];
    [self doNetworking];
}
- (void)doNetworking {
     NSString *urlString = [NSString stringWithFormat:@"%@%@",Domain,getAllOrderAndContrForCosApi];
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:100];
    [dic setValue:@"2" forKey:@"queryType"];
    [dic setValue:self.model.orderId forKey:@"orderId"];
    [dic setValue:self.model.contrId forKey:@"contrId"];
    [[NetworkManager manager] sendPostRequestWithUrl:urlString paramenters:dic success:^(id responseObject) {
        NSLog(@"成功%@",responseObject);
        if([responseObject[@"code"]  isEqual: @1]){
            self.dataSourceArray = [DataManager getOrderListData:responseObject];
            NSLog(@"======%@",self.dataSourceArray);
            [self dealWithData];
            [self.tableView reloadData];
        }else{
            [QMUITips showInfo:responseObject[@"msg"] inView:self.view hideAfterDelay:1];
        }
    } failure:^(NSError *error) {
        NSLog(@"失败%@",error);
    }];
    
}
- (void)dealWithData{
    orderModel *model = self.dataSourceArray[0];
    [self.sourceArray addObject:model.ownerName?model.ownerName:@"-"];
    [self.sourceArray addObject:model.ownerMobile?model.ownerMobile:@"-"];
    [self.sourceArray addObject:model.createTimeOfYX?model.createTimeOfYX:@"-"];
    [self.sourceArray addObject:[NSString stringWithFormat:@"%@%@%@",model.province,model.city,model.area]];
    [self.sourceArray addObject:model.budgetName?model.budgetName:@"-"];
    [self.sourceArray addObject:model.planzxDate?model.planzxDate:@"-"];
    [self.sourceArray addObject:model.size?model.size:@"-"];
    [self.sourceArray addObject:model.typeName?model.typeName:@"-"];
    [self.sourceArray addObject:model.zxTypeName?model.zxTypeName:@"-"];
    [self.sourceArray addObject:model.remark?model.remark:@"无"];
}
- (void)initUI {
   self.array = @[ @"预约人",@"联系方式",@"预约时间",@"装修区域",@"计划装修时间",@"房屋面积",@"房屋类型",@"装修类型",@"备注说明"];
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRects(0, 0, 375, 96)];
    img.image = [UIImage imageNamed:self.model.styleLikeName];

//    [self.view addSubview:img];
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRects(0, 0, 375, 667) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = [UIColor colorWithRed:245.0/255.0 green:244.0/255.0 blue:248.0/255.0 alpha:1.0];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableHeaderView = img;
    [self.view addSubview:self.tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderDetaileTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(cell == nil){
        cell = [[OrderDetaileTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.titleLabel.text = self.array[indexPath.row];
    if(self.sourceArray.count > 0){
        cell.contentLabel.text = self.sourceArray[indexPath.row];
    }
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
